﻿// -----------------------------------------------------------------------
// <copyright file="CustomGraphicEqualizer.cs" company="Abyssalsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Gui.ControlBuilders
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Xml;
    using Metal.Config;
    using Gui.ThemeEngine;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class CustomGraphicEqualizer : BaseControl
    {
        /// <summary>
        /// Create the custom control
        /// </summary>
        /// <param name="controlProperties">The Xml node that contains the control properties</param>
        /// <returns>Returns custom control</returns>
        public Core.Player.Masks.GraphicEqMask GetControl(XmlNode controlProperties)
        {
            string strThemeName = Settings.Instance.GetValue("LastSettings.Theme", "BlackMetal");

            Core.Player.Masks.GraphicEqMask customGraphicEq = new Core.Player.Masks.GraphicEqMask();

            // Apply common properties
            this.BuildControl(controlProperties, customGraphicEq as Control);

            customGraphicEq.Visualisation.BackColor = PropertyProvider.GetValue(controlProperties, "backColor");
            customGraphicEq.Visualisation.Color1 = PropertyProvider.GetValue(controlProperties, "color1");
            customGraphicEq.Visualisation.Color2 = PropertyProvider.GetValue(controlProperties, "color2");
            customGraphicEq.Visualisation.Linear = PropertyProvider.GetValue(controlProperties, "linear", false);
            customGraphicEq.Visualisation.FullSpectrum = PropertyProvider.GetValue(controlProperties, "fullSpectrum", false);
            customGraphicEq.Visualisation.HighQuality = PropertyProvider.GetValue(controlProperties, "highQuality", true);
            customGraphicEq.Visualisation.LineWidth = PropertyProvider.GetValue(controlProperties, "lineWidth", 2);
            customGraphicEq.Visualisation.Distance = PropertyProvider.GetValue(controlProperties, "distance", 2);

            // Specific attributes
            XmlNode ellipseStyle = controlProperties.SelectSingleNode("SpectrumEllipseStyle");
            if (ellipseStyle != null)
            {
                customGraphicEq.Visualisation.EllipseWidth = PropertyProvider.GetValue(ellipseStyle, "ellipseWidth", 1);
            }

            XmlNode dotStyle = controlProperties.SelectSingleNode("SpectrumDotStyle");
            if (dotStyle != null)
            {
                customGraphicEq.Visualisation.DotWidth = PropertyProvider.GetValue(dotStyle, "dotWidth", 2);
            }

            XmlNode waveStyle = controlProperties.SelectSingleNode("SpectrumWaveStyle");
            if (waveStyle != null)
            {
                customGraphicEq.Visualisation.WaveWidth = PropertyProvider.GetValue(waveStyle, "waveWidth", 1);
            }

            XmlNode peakStyle = controlProperties.SelectSingleNode("SpectrumLinePeakStyle");
            if (peakStyle != null)
            {
                customGraphicEq.Visualisation.Color3 = PropertyProvider.GetValue(peakStyle, "color3");
                customGraphicEq.Visualisation.PeakWidth = PropertyProvider.GetValue(peakStyle, "peakWidth", 2);
                customGraphicEq.Visualisation.PeakDelay = PropertyProvider.GetValue(peakStyle, "peakDelay", 5);
            }

            XmlNode beanStyle = controlProperties.SelectSingleNode("SpectrumBeanStyle");
            if (beanStyle != null)
            {
                customGraphicEq.Visualisation.BeanWidth = PropertyProvider.GetValue(beanStyle, "beanWidth", 2);
            }

            customGraphicEq.Enabled = false;

            return customGraphicEq;
        }

        /// <summary>
        /// Apply common properties
        /// </summary>
        /// <param name="control">The Xml node that contains our control properties</param>
        /// <param name="customControl">The custom control that will be created</param>
        public override void BuildControl(System.Xml.XmlNode control, System.Windows.Forms.Control customControl)
        {
            base.BuildControl(control, customControl);
        }
    }
}
